package per.ethan.ssm.domain;

import cn.hutool.http.HttpStatus;
import lombok.Data;

/**
 * @author Ethan
 * @date 2020/03/10 19:57
 */

@Data
public class ResultBean<T> {

    private String message;

    private int code = HttpStatus.HTTP_OK;

    private T data;

    private ResultBean() {}

    private ResultBean(T data) {
        this.data = data;
    }

    private ResultBean(T data, String message) {
        this.data = data;
        this.message = message;
    }

    private ResultBean(ErrorCodeVO errorCodeVO) {
        if (null != errorCodeVO) {
            this.code = errorCodeVO.getCode();
            this.message = errorCodeVO.getMessage();
        }
    }

    public static <T> ResultBean<T> success(T data) {
        return new ResultBean<>(data);
    }

    public static <T> ResultBean<T> success(T data, String message) {
        return new ResultBean<>(data, message);
    }

    public static <T> ResultBean<T> error(ErrorCodeVO errorCodeVO) {
        return new ResultBean<>(errorCodeVO);
    }

}
